#include <stdio.h>
#include <stdlib.h>
#include "simpleTime.h"

#define F_NAME_BUFF_SIZE 50

#define HELP_DOC \
	"\nUsage: show_video directory num_of_images framerate \n\n" \
	"The jpg(s) should be named from 0 to num_of_images."
	
int lcd_open(const char *str); //init lcd
void close_lcd(void);  //close lcd
int lcd_draw_jpg_in_jpg(unsigned int x,unsigned int y, \
	const char *pjpg_path,char *pjpg_buf,unsigned int jpg_buf_size);

int main(int argc, char **argv) {
	/* Extract arguments */
	if (argc < 4) {
		printf(HELP_DOC);
		exit(-1);
	}
	const char *path = argv[1];
	int num_of_img = atoi(argv[2]);
	int framerate = atoi(argv[3]);
	
	
	/* Begin to display */
	lcd_open("/dev/fb0");
	
	/* Play the images continuously with given framerate*/
	for (int i=0; i<=num_of_img; i++){
		char filename[F_NAME_BUFF_SIZE] = "";
		sprintf(filename, "%s/%d.jpg", path, i);
		debug_info("playing file: %s\n", filename);
		
		lcd_draw_jpg_in_jpg(0, 0, filename, NULL, 0);
		rate(framerate);
	}
	
	delay(2000);
	
	close_lcd();
	return 0;
}
